package pers.cz.javacvdemo.video;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @version 1.0
 * @description:
 * @author: ChengZhi 0336
 * @create: 2025-08-12 17:22
 **/
public class CustomerThreadPool {

	public static ExecutorService INSTANCE = createSingleThreadExecutor();

	public static ExecutorService createSingleThreadExecutor() {
		return new ThreadPoolExecutor(
				3,
				Integer.MAX_VALUE,
				60L,
				TimeUnit.SECONDS,
				new SynchronousQueue<>(),
				new ThreadFactory() {
					private final AtomicInteger threadNumber = new AtomicInteger(1);
					@Override
					public Thread newThread(Runnable r) {
						Thread thread = new Thread(r, "transform-thread-" + threadNumber.getAndIncrement());
						thread.setDaemon(false);
						thread.setPriority(Thread.NORM_PRIORITY);
						return thread;
					}
				},
				new ThreadPoolExecutor.CallerRunsPolicy()
		);
	}

	public static void execute(Runnable runnable) {
		INSTANCE.execute(runnable);
	}
}
